import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

// 导入动态路由
import ArticleRouter from './modules/planmanagement'

// 静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/workstation',
    meta: { title: '我的工作站', icon: 'dashboard' },
    children: [{
      path: 'workstation',
      name: 'workstation',
      component: () => import('@/views/workstation/index'),
      meta: { title: '我的首页', icon: 'dashboard' }
    },{
      path: 'patient',
      name: 'patient',
      component: () => import('@/views/workstation/patient'),
      meta: { title: '我的患者', icon: 'dashboard' }
    },{
      path: 'messageCenter',
      name: 'messageCenter',
      component: () => import('@/views/workstation/messageCenter'),
      meta: { title: '消息中心', icon: 'dashboard' }
    },]
  },

  {
    path: '/formmanagement',
    component: Layout,
    redirect: '/formmanagement',
    meta: { title: '表单管理', icon: 'dashboard' },
    children: [{
      path: 'audioForm',
      component: () => import('@/views/formmanagement/audioForm'),
      meta: { title: '语音表单', icon: 'dashboard' },
      children: [{
        path: 'audioFile',
        name: 'audioFile',
        component: () => import('@/views/formmanagement/audioForm/audioFile'),
        meta: { title: '语音文件管理', icon: 'dashboard' }
      },{
        path: 'generalLibrary',
        name: 'generalLibrary',
        component: () => import('@/views/formmanagement/audioForm/generalLibrary'),
        meta: { title: '通用库管理', icon: 'dashboard' }
      },{
        path: 'diseaseIndex',
        name: 'diseaseIndex',
        component: () => import('@/views/formmanagement/audioForm/diseaseIndex'),
        meta: { title: '疾病指标', icon: 'dashboard' }
      },{
        path: 'atlasProblem',
        name: 'atlasProblem',
        component: () => import('@/views/formmanagement/audioForm/atlasProblem'),
        meta: { title: '图谱问题', icon: 'dashboard' }
      },{
        path: 'semanticTemplate', 
        name: 'semanticTemplate',
        component: () => import('@/views/formmanagement/audioForm/semanticTemplate'),
        meta: { title: '语义模板', icon: 'dashboard' }
      },{
        path: 'gaugePlan',
        name: 'gaugePlan',
        component: () => import('@/views/formmanagement/audioForm/gaugePlan'),
        meta: { title: '量表方案', icon: 'dashboard' }
      },]
    },{
      path: 'pageForm',
      name: 'pageForm',
      component: () => import('@/views/formmanagement/pageForm'),
      meta: { title: '页面表单', icon: 'dashboard' }
    }]
  },
  // 将来404 这里要注释掉，要放在路由配置的最后
  { path: '*', redirect: '/404', hidden: true } 
]

// 动态路由
export const asyncRoutes = [ArticleRouter]

// 创建路由实例的函数
const createRouter = () => new Router({
  mode:'hash',
  scrollBehavior: () => ({ y: 0 }),
  // TODO: 没做权限之间
  routes: [...constantRoutes, ...asyncRoutes]
  // TODO: 做了权限之后
  // routes: [...constantRoutes]
})
// 创建路由实例 
const router = createRouter()
// 重置路由实例
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
// 暴露路由实例
export default router
